package pers.vicxu.springbootdemo.controller;

import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.vicxu.springbootdemo.dto.ResponseMessage;
import pers.vicxu.springbootdemo.dto.User;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by Vic Xu on 2018/8/18
 */
@RestController
public class LoginController {

    @PutMapping(value = "/login", consumes = "application/json")
    public ResponseMessage login(HttpServletRequest request, User user) {
        ResponseMessage message = new ResponseMessage();
        if ("vicxu".equals(user.getName()) && "123".equals(user.getPwd())) {
            request.getSession().setAttribute("name", user.getName());
            message.setCode(200);
            message.setContent("LoginSuccess");
        } else {
            message.setCode(200);
            message.setContent("LoginFailed");
        }
        return message;
    }
}

